ev_cars <- read_csv("ElectricCarData_Clean.csv")
## Rows: 103 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): Brand, Model, FastCharge_KmH, RapidCharge, PowerTrain, PlugType, Bo...
## dbl (6): AccelSec, TopSpeed_KmH, Range_Km, Efficiency_WhKm, Seats, PriceEuro
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
summary(ev_cars)
##     Brand              Model              AccelSec       TopSpeed_KmH  
##  Length:103         Length:103         Min.   : 2.100   Min.   :123.0  
##  Class :character   Class :character   1st Qu.: 5.100   1st Qu.:150.0  
##  Mode  :character   Mode  :character   Median : 7.300   Median :160.0  
##                                        Mean   : 7.396   Mean   :179.2  
##                                        3rd Qu.: 9.000   3rd Qu.:200.0  
##                                        Max.   :22.400   Max.   :410.0  
##     Range_Km     Efficiency_WhKm FastCharge_KmH     RapidCharge       
##  Min.   : 95.0   Min.   :104.0   Length:103         Length:103        
##  1st Qu.:250.0   1st Qu.:168.0   Class :character   Class :character  
##  Median :340.0   Median :180.0   Mode  :character   Mode  :character  
##  Mean   :338.8   Mean   :189.2                                        
##  3rd Qu.:400.0   3rd Qu.:203.0                                        
##  Max.   :970.0   Max.   :273.0                                        
##   PowerTrain          PlugType          BodyStyle           Segment         
##  Length:103         Length:103         Length:103         Length:103        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Seats         PriceEuro     
##  Min.   :2.000   Min.   : 20129  
##  1st Qu.:5.000   1st Qu.: 34430  
##  Median :5.000   Median : 45000  
##  Mean   :4.883   Mean   : 55812  
##  3rd Qu.:5.000   3rd Qu.: 65000  
##  Max.   :7.000   Max.   :215000
ev_cars <- ev_cars%>%
  mutate(Range_Miles = round(Range_Km * 0.621371,0)) %>%
  mutate(PriceDollars = round(PriceEuro * 1.09))
ev_cars_top10 <- ev_cars[order(-ev_cars$Range_Miles),]
#View(ev_cars_top10)

ev_cars_top10 <- ev_cars_top10[1:10,]

ev_cars_top10 %>%
  ggplot(aes(fill =Model, y = Range_Miles, x = Brand)) + 
  geom_bar(position="dodge", stat="identity") +
  xlab("Electric Vehicles") +
  ylab("Range in Miles") +
  ggtitle("Range in Miles for Top 10 EV Models") +
  theme(plot.title = element_text(hjust = 0.5),axis.text.x = element_text(angle = 45)) +
  scale_fill_brewer(type = "qual", palette = 3)

ev_cars_mean_effi_brand <- ev_cars %>%
  group_by(Brand) %>%
  summarise(mean_efficiency = round(mean(Efficiency_WhKm),0))

ev_cars_mean_effi_brand <- ev_cars_mean_effi_brand[order(-ev_cars_mean_effi_brand$mean_efficiency),]
ev_cars_mean_effi_brand %>%
  mutate(Brand = fct_rev(fct_reorder(Brand, mean_efficiency))) %>%
  head(n = 20) %>%
  ggplot(aes(Brand, mean_efficiency,fill = Brand)) +
  geom_bar(position="dodge", stat="identity") +
  xlab("Brand") +
  ylab("Mean Efficiency") +
  ggtitle("Top 20 Brands by Mean Efficiency") +
  theme(plot.title = element_text(hjust = 0.5),axis.text.x = element_text(angle = 45), legend.position="none") 

  #scale_fill_brewer(type = "qual", palette="Dark2")

Including Plots

You can also embed plots, for example:

ev_cars %>%
  ggplot(aes(BodyStyle, PriceDollars, fill = BodyStyle)) +
  geom_boxplot() +
  xlab("Body Style") +
  ylab("Price in Dollars") +
  ggtitle("Price by Body Style") +
  theme(plot.title = element_text(hjust = 0.5), legend.position="none") 

  #scale_fill_brewer(type = "qual", palette = 2)
  

#ggplotly()
ev_cars %>%
  filter(Brand == "Tesla") %>%
  ggplot(aes(x = Model, y = PriceDollars, size = Range_Miles, color = BodyStyle)) +
  geom_point(alpha = 0.5) +
  scale_size(range = c(1, 15)) +
  xlab("Tesla Models") +
  ylab("Price in Dollars") +
  ggtitle("A Closer Look at the Different Tesla Models") + 
  theme(plot.title = element_text(hjust = 0.5),axis.text.x = element_text(angle = 90))

ggplotly()